package testdemo;
//生成图片
import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.model.image.Text2ImageResponse;
import java.util.Scanner;

public class demo3 {
    public static void main(String[] args) {
        // 直接在代码中设置访问密钥和密钥
        String accessKey = "ALTAKtcDh0nQtP40NgZUAmDA4K";
        String secretKey = "57a949833c7b408a81e06959785d90cf";

        // 创建 Qianfan 实例
        Qianfan qianfan = new Qianfan(accessKey, secretKey);

        // 创建 Scanner 实例获取用户输入
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入提示词: ");
        String prompt = scanner.nextLine();

        // 调用文本生成图片的方法
        try {
            Text2ImageResponse response = qianfan.text2Image()
                    .prompt(prompt)
                    .execute();
            System.out.println(response.getData().get(0).getB64Image());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            scanner.close();
        }
    }
}
